import threading

from helpFunc import *
import time
import select
def doTest(sock):
    sock.setblocking(0)
    readBuf = b''
    writeBuf = b''
    readCo = writeCo = 0
    staTime = time.time()
    while True:
        r = select.select([sock],[sock],[],1)
        if r[0]:
            readBuf += sock.recv(10000000)
            while True:
                msg = TOUMsg()
                ret,readBuf = msg.unpack(readBuf)
                if not ret:
                    break
                readCo += 1
              
        if r[1]:
            if not writeBuf:
                writeBuf = TOUMsg({},b's'*random.randint(10,2000)).pack()
                writeCo += 1
            n = sock.send(writeBuf)
            writeBuf = writeBuf[n:]
        if time.time()-staTime>1:
            print (staTime,readCo,writeCo)
            readCo = writeCo = 0
            staTime = time.time()            
            
          